﻿var returnurl = '';
var messagebox_timer;
$.fn.messagebox = function(message, url, type, delay, iw, ih) {
	clearTimeout(messagebox_timer);
	$("#msgprint").remove();
	var m_body = $(this), timer = false;
	delay = (typeof delay == "undefined" ? 5000 : delay);
	returnurl = url;
	var box_style = 'position:absolute;display:none;z-index:3001;padding:10px 30px 10px 40px;';
	switch (type) {
	case 1:
		box_style += 'border:1px solid Green;color:#090;background:url(images/ico-success.gif) 10px 10px no-repeat #F1FEF2;';
		break;
	case 0:
		box_style += 'border:1px solid Red;color:#EE1010;background:url(images/ico-error.gif) 10px 10px no-repeat #FDF8E8;';
		break;
	default:
		box_style += 'border:1px solid Orange;color:Orange;background:url(images/warning.png) 10px 10px no-repeat #FEFDE9;';
		break
	}
	var str = "<div id=\"msgprint\" style=\"" + box_style + "\">" + message
			+ "</div>";
	m_body.append(str);
	var dom_obj = document.getElementById("msgprint");
	var ext_width = $("#msgprint").width();
	if(ih == null){
		dom_obj.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight
				- dom_obj.offsetHeight - $("#msgprint").height()) / 2)
				+ "px";	
	}else{
		dom_obj.style.top = ((ih + $("#msgprint").height()) / 2)
				+ "px";
	}
	if(iw == null){
		dom_obj.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth
				- dom_obj.offsetWidth - $("#msgprint").width()) / 2)
				+ "px";
	}else{
		dom_obj.style.left = ((iw - $("#msgprint").width()) / 2)
				+ "px";
	}
	
	$("#msgprint").fadeIn(1000, function() {
		messagebox_timer = setTimeout(messagebox_out, delay)
	})
};
function messagebox_out() {
	if (returnurl == undefined || returnurl == '') {
		$("#msgprint").fadeOut(500);
	}
	if (returnurl == "back") {
		this.history.back(-1)
	} else if (returnurl != "" && returnurl != undefined) {
		this.location.href = returnurl
	}
}
function info(message, url, type, delay){
	$("body").messagebox(message, url, type, delay, null, null);
}
function _info(message, url, type, delay, width, height){
	$("body").messagebox(message, url, type, delay, width, height);
}
function succeed(message){
	$("body").messagebox(message, '', 1, 1000, null, null);
}
function error(message){
	$("body").messagebox(message, '', 0, 1000, null, null);
}
function error(message,delay){
	$("body").messagebox(message, '', 0, delay, null, null);
}